#include <iostream>
#include <vector>
using namespace std;

class Solution {
public:
    vector<int> sortColors(vector<int>& nums) {
        int n = nums.size();
        vector<int> x(3, 0);
        // 遍历数组
        for (int i = 0; i < n; i++)
        {
            x[nums[i]]++;
        }
        int k = 0;
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < x[i]; j++)
            {
                nums[k++] = i;
            }
        } 
        return nums;
    }
};

int main(){

    vector<int> v;
    v.push_back(1);
    v.push_back(0);
    v.push_back(2);
    v.push_back(1);
    v.push_back(0);
    v.push_back(2);
    Solution s;
    vector<int> res = s.sortColors(v);
    for (vector<int>::iterator it = res.begin(); it < res.end(); it++)
    {
        cout << *it << endl;
    }
    

    return 0;
}